class Solution(object):
    def lengthOfLongestSubstring(self, s):  # O(n)
        """
        :type s: str
        :rtype: int
        """
        curr_string = ""  # longest_ending_here
        max_length = 0
        for c in s:
            if c in curr_string:
                curr_string = curr_string[curr_string.index(c)+1:] + c
            else:
                curr_string += c
            if len(curr_string) > max_length:
                max_length = len(curr_string)
        return max_length


if __name__ == "__main__":
    soln = Solution()
    print(soln.lengthOfLongestSubstring(""))
    print(soln.lengthOfLongestSubstring("wdvcs"))
    print(soln.lengthOfLongestSubstring("abcabcbb"))
    print(soln.lengthOfLongestSubstring("pwwkew"))
    print(soln.lengthOfLongestSubstring("bbbbb"))
    print(soln.lengthOfLongestSubstring("dvdf"))
